package com.capgemini.business.controller;

import com.capgemini.business.mapper.dataobject.EmployeeRecords;
import com.capgemini.business.service.EmployeeRecordsService;
import com.capgemini.commons.response.Response;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/employees")
public class EmployeeRecordsController {



    @Resource
    private EmployeeRecordsService employeeRecordsService;

    @GetMapping("/list")
    public Response<List<EmployeeRecords>> list() {
        return Response.success(employeeRecordsService.list());
    }

    @GetMapping("/get/{id}")
    public Response<EmployeeRecords> getById(@PathVariable Integer id) {
        return Response.success(employeeRecordsService.findById(id));
    }

    @PostMapping("/add")
    public Response<String> save(@RequestBody EmployeeRecords employee) {
        employeeRecordsService.save(employee);
        return Response.success("success");
    }

    @PostMapping("/update")
    public Response<String> update(@RequestBody EmployeeRecords employee) {
        employeeRecordsService.update(employee);
        return Response.success("success");
    }

    @DeleteMapping("/delete/{id}")
    public Response<String> delete(@PathVariable Integer id) {
        employeeRecordsService.delete(id);
        return Response.success("success");
    }

}
